// pages/sharebox/shareDevList/shareDevList.js
var app = getApp();
var _PAGE = 1;
var _PAGESIZE = 10;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ways: '',
    msgList: [],
    hasMore: false,
    load: true,
    loading: false
  },

  /**_urlurlrr
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var ways = options.ways || 1;
    that.setData({
      ways: ways
    })
    console.log(that.data.ways);

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    _PAGE = 1;
    that.getMsg()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    if (!that.data.hasMore) {
      return false;
    }
    _PAGE++;
    that.setData({
      loading: true
    })
    that.getMsg();
  },
  //跳转共享用户
  goShareUser: function() {
    wx.navigateTo({
      url: '../shareUser/shareUser',
    })
  },
  //跳转共享详情
  goShareDevDetail: function() {
    wx.navigateTo({
      url: '../shareDevDetail/shareDevDetail',
    })
  },

  getMsg() {
    var that = this;
    app.ajax({
      url: "User/Shared/sharedMessage",
      data: {
        page: _PAGE,
        row: _PAGESIZE,
      },
      success: function(res) {
        if (res.data.code == 1000) {
          if (_PAGE == 1) {
            that.setData({
              msgList: res.data.data.data
            })
          } else {
            that.setData({
              msgList: that.data.msgList.concat(res.data.data.data)
            })
          }
          // 是否加载更多
          var hasMore = true;
          if (res.data.data.data.length < _PAGESIZE) {
            hasMore = false;
          }
          that.setData({
            hasMore: hasMore,
            load: false,
            loading: false
          });
        } else {
          if (_PAGE == 1) {
            that.setData({
              hasMore: false,
              loading: false
            })
          } else {
            that.setData({
              hasMore: false,
              loading: false
            })
          }
        }
      }
    })
  }
})